//
//  AUNavVC.swift
//  swift_airu
//
//  Created by A on 2025/9/20.
//

import UIKit

class AUNavVC: UINavigationController {
    // MARK: - 属性
   

       // MARK: - 生命周期
       override func viewDidLoad() {
           super.viewDidLoad()
//           let navHeight = AUConfig.shared.navigationBarHeight
//           
//           let kStatusBarHeight = AUConfig.shared.statusBarHeight
//           let safeAreaTop = AUConfig.shared.safeAreaTop
//           let safeAreaBottom = AUConfig.shared.safeAreaBottom
//       
//           let isNotchScreen = AUConfig.shared.isNotchScreen
//           let navHeight2 = AUConfig.shared.navigationBarHeight
//           
           
           if #available(iOS 13.0, *) {
               let appearance = UINavigationBarAppearance()
               appearance.configureWithOpaqueBackground()          // 不透明背景
               appearance.backgroundColor = .white                // 导航栏背景色
               appearance.titleTextAttributes = [.foregroundColor: UIColor.black] // title颜色

               navigationBar.standardAppearance = appearance
               navigationBar.scrollEdgeAppearance = appearance
           } else {
               // iOS 12及以下
               navigationBar.barTintColor = .white
               navigationBar.isTranslucent = false
               navigationBar.titleTextAttributes = [.foregroundColor: UIColor.black]
           }

       }


       
       // MARK: - Push 时自定义返回按钮
       override func pushViewController(_ viewController: UIViewController, animated: Bool) {
           if viewControllers.count > 0 {
               viewController.hidesBottomBarWhenPushed = true
               let backButton = UIButton(type: .system)
               let statusBarHeight = AUConfig.shared.statusBarHeight
               let navBarHeight = AUConfig.shared.navigationBarHeight
               backButton.setImage(UIImage(systemName: "chevron.left"), for: .normal)
               backButton.tintColor = .black
               backButton.addTarget(self, action: #selector(customBack), for: .touchUpInside)
               backButton.frame = CGRect(x: 0, y: statusBarHeight, width: 44, height: navBarHeight) // y: 状态栏高度适配
               
               viewController.view.addSubview(backButton)
           }
           super.pushViewController(viewController, animated: animated)
       }
       
       @objc private func customBack() {
           popViewController(animated: true)
       }
       
       // MARK: - 状态栏样式
//       override var preferredStatusBarStyle: UIStatusBarStyle {
//           return .darkContent
//       }

}
